#include <iostream>
#include <pthread.h>
#include "libnet.h"

using namespace std;

void *readInput(void *arg)
{
  SocketClient *client = (SocketClient*)(arg);
  string line = "";
  while(line != "exit")
    {
      line = client->readLine();
      cout << line << endl;
    }
}

int main(int argc, char **argv)
{
  if(argc < 3)
    {
      cerr << "Error : A port and an ip are needed to start the server" << endl;
      return 0;
    }
  
  SocketClient client(argv[1], atoi(argv[2]));

  pthread_t read;
  pthread_create(&read, NULL, readInput, (void*)&client);

  string line = "";
  while(line != "exit" && line != "quit")
    {
      getline(cin, line);
      client.writeLine(line.c_str());
    }
  
  return 0;
}
